<%--
  Created by IntelliJ IDEA.
  User: ？
  Date: 2021/11/8
  Time: 9:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>

    <style>
        .bgcRed{
            background-color: red;
        }
        .bgcGreen{
            background-color: green;
        }


    </style>
    <script src="js/jquery-3.6.0.min.js"></script>
    <script>

        $(function () {

            $("#username").blur(function () {

                let  url = "${pageContext.request.contextPath}/helloServlet"

                let params = {
                    "method":"checkUsername",
                    "username":$(this).val()
                }

                let  callback = function (rel) {
                    // alert(rel)
                    $("#usernameInfo").html(rel.message)
                    // $.post(url,params,callback())
                    if (rel.flag == true) {

                        $("#usernameInfo").removeClass("bgcRed");

                        $("#usernameInfo").addClass("bgcGreen");


                        $("#btn01").prop("disabled","")

                    } else {

                        $("#usernameInfo").removeClass("bgcGreen");
                        $("#usernameInfo").addClass("bgcRed");

                        $("#btn01").prop("disabled","disabled")
                    }

                }

                $.post(url,params,callback,"json")
        })

        })

        function btn01() {

            alert("提交")
        }

    </script>
</head>
<body>

<input type="text" name="username" id = "username" placeholder="请输入用户名" > <span id ="usernameInfo"></span>

<input type="button" value="提交"  onclick="btn01()">


</body>
</html>
